/*
  Copyright (c) 2011, Mikheev Rostislav
  Copyright (c) 2011, FreshFarsh team

  Steel Engine source code is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
/**
  @author Mikheev Rostislav <hacenator@gmail.com>
  @date 26.03.2010
  @brief Basic graphical structures operations source code
*/

#include "structures.h"

namespace _STEEL_NAMESPACE {

/*
 * Rect
 */
Rect::Rect(int top, int right, int bottom, int left)
  : left(left),
  right(right),
  bottom(bottom),
  top(top)
{
}

/*
 * Point2i
 */
Point2i::Point2i(float x, float y) {
  this->x = static_cast<int>(x);
  this->y = static_cast<int>(y);
}

Point2i& Point2i::operator=(const Point2f& point) {
  x = point.x;
  y = point.y;
//  return this*;
};

/*
 * Point2f
 */
Point2f::Point2f(float x, float y) {
  this->x = x;
  this->y = y;
}

Point2f& Point2f::operator=(const Point2i& point) {
  x = point.x;
  y = point.y;
//  return this*;
};

/*
 * RGBA
 */
RGBAColor::RGBAColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
  : r(r),
  g(g),
  b(b),
  a(a)
{
}

RGBAColor& RGBAColor::operator=(RGBColor& color) {
  r = color.r;
  g = color.g;
  b = color.b;
  a = 255;
}

/*RGBAColor& RGBAColor::operator=(std::initializer_list<uint8_t> il) {
  // std::copy(v, v+2, il.begin());
  // or std::copy(x.begin(), x.end(), il.begin());
  v.fill(il.begin());
}*/

/*
 * RGB
 */
RGBColor::RGBColor(uint8_t r, uint8_t g, uint8_t b)
  : r(r),
  g(g),
  b(b)
{
}

RGBColor& RGBColor::operator=(RGBAColor& color) {
  r = color.r;
  g = color.g;
  b = color.b;
}

/*
 * Quad2D
 */
Quad2D& Quad2D::operator=(const Rect &rect) {
  vertex[0].point.x = rect.left;
  vertex[0].point.y = rect.bottom;
  vertex[0].texture.x = 0;
  vertex[0].texture.y = 0;

  vertex[1].point.x = rect.right;
  vertex[1].point.y = rect.bottom;
  vertex[1].texture.x = 1;
  vertex[1].texture.y = 0;

  vertex[2].point.x = rect.right;
  vertex[2].point.y = rect.top;
  vertex[2].texture.x = 1;
  vertex[2].texture.y = 1;

  vertex[3].point.x = rect.left;
  vertex[3].point.y = rect.top;
  vertex[3].texture.x = 0;
  vertex[3].texture.y = 1;

  //return this;
}

}
